
package com.googlecode.cswish.oosearch;

import java.io.Serializable;

/**
 * @author Jerry.Feng Date: 2005-2-27 21:12:27
 * @version $id: $
 */
public class Condition implements Serializable {

	private static final long serialVersionUID = 3689632514595895608L;

	
	public static final String LOGIC_AND = " and ";
	public static final String LOGIC_OR = " or ";
	
	public static final String COMPARE_EQUAL = "=";
	public static final String COMPARE_LIKE = " like ";
	public static final String COMPARE_NOT_LIKE = " not like ";
	public static final String COMPARE_AUTO_EQFIRST = " auto ";
	public static final String COMPARE_AUTO_LIKEFIRST = " autolike ";
	
	public static final char FLAG_LIKE_FIRST = '^';
	public static final char FLAG_LIKE = '%';
	public static final char FLAG_EQUALS = '=';
	public static final char FLAG_NOT_EQUALS = '!';
	public static final char FLAG_LARGE = '>';
	public static final char FLAG_LESS = '<';
	
	public static final Condition DEFAULT = new Condition();
	public static final Condition SEARCH_LIKEFIRST = new Condition();
	public static final Condition ADVANCE_SEARCH = new Condition();
	public static final Condition SEARCH_ONE = new Condition();
	static {
		SEARCH_ONE.setSize(1);
		SEARCH_LIKEFIRST.setCompareFlag(COMPARE_AUTO_LIKEFIRST);
		ADVANCE_SEARCH.setCompareFlag(COMPARE_AUTO_LIKEFIRST);
		ADVANCE_SEARCH.setEnableComplexSearch(true);
	}

	// ------------------------- property ---------------------------
	// combine parameter by " and "
	private String logicFlag = LOGIC_AND;

	// compare the parameter according to the object type
	private String compareFlag = COMPARE_AUTO_EQFIRST;

	private boolean enableComplexSearch;
	
	private String sort;
	
	private String dir;
	
	private int offset;

	private int size;

	public String getCompareFlag() {
		return compareFlag;
	}
	
	public void setCompareFlag(String compareFlag) {
		this.compareFlag = compareFlag;
	}
	
	public String getLogicFlag() {
		return logicFlag;
	}
	
	public void setLogicFlag(String logicFlag) {
		this.logicFlag = logicFlag;
	}
	
	public int getOffset() {
		return offset;
	}
	
	public void setOffset(int offset) {
		if (offset < 0) {
			offset = 0;
		}
		this.offset = offset;
	}
	
	public int getSize() {
		return size;
	}
	
	public void setSize(int size) {
		if (size < 0) {
			size = 0;
		}
		this.size = size;
	}
	
	public boolean isEnableComplexSearch() {
		return enableComplexSearch;
	}
	
	public void setEnableComplexSearch(boolean enableComplexSearch) {
		this.enableComplexSearch = enableComplexSearch;
	}
	
	public String getSort() {
		return sort;
	}

	public void setSort(String sort) {
		this.sort = sort;
	}

	public String getDir() {
		return dir;
	}

	public void setDir(String dir) {
		this.dir = dir;
	}

	public Object clone() {
		Condition condition = new Condition();
		condition.setCompareFlag(this.getCompareFlag());
		condition.setLogicFlag(this.getLogicFlag());
		condition.setOffset(this.getOffset());
		condition.setSize(this.getSize());
		condition.setEnableComplexSearch(this.isEnableComplexSearch());
		condition.setSort(sort);
		condition.setDir(dir);
		return condition;
	}
}